/**
 * Copyright (c) 2010-2011 Pierre Labatut
 *
 * This file is part of Space-Chronicles project.
 *
 * Space-Chronicles is free software: you can redistribute it and/or modify it
 * under the terms of its license which may be found in the accompanying
 * LICENSE file or <http://code.google.com/p/space-chronicles/>.
 */
package space.input;

import net.java.games.input.Component;
import net.java.games.input.Component.Identifier;
import net.java.games.input.Controller;
import net.java.games.input.EventQueue;
import net.java.games.input.Rumbler;
import space.input.Record.Frame;

/**
 *
 * @author Pierre Labatut
 */
public class RecordControler implements Controller {

    final private Controller controller;
    final private Record record;

    public RecordControler(final Controller controller, Record record) {
        if (controller == null) {
            throw new NullPointerException();
        }
        if (record == null) {
            throw new NullPointerException();
        }
        this.controller = controller;
        this.record = record;

    }

    public Controller[] getControllers() {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public Type getType() {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public Component[] getComponents() {
        return new Component[]{};
    }

    public Component getComponent(Identifier idntfr) {
        return controller.getComponent(idntfr);
    }

    public Rumbler[] getRumblers() {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public boolean poll() {
        final boolean r = controller.poll();
        final Frame f = record.addFrame();
        for (Component c : controller.getComponents()) {
            final Frame cf = new Frame();            
            cf.putFloat("PollData", c.getPollData());
            cf.putFloat("DeadZone", c.getDeadZone());
            //cf.putBoolean("Analog", c.isAnalog());
            //cf.putBoolean("Relative", c.isAnalog());            
            f.putFrame(c.getIdentifier().getName(), cf);
        }
        return r;
    }

    public void setEventQueueSize(int i) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public EventQueue getEventQueue() {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public PortType getPortType() {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public int getPortNumber() {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public String getName() {
        return controller.getName();
    }
}
